package com.cungmua.app.model.request;

import com.cungmua.app.utils.AppConfig;
import com.cungmua.app.utils.JsonUtils;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.Serializable;
import java.util.Map;

/**
 * Created by kelvin.nguyen on 6/16/14.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class CungMuaRequest implements Serializable {
    private String deviceId;

    @JsonCreator
    protected CungMuaRequest(@JsonProperty("DeviceId") String deviceId) {
        this.deviceId = deviceId;
    }

    @JsonProperty("Version")
    public int getVersion() {
        return AppConfig.getApiVersion();
    }

    @JsonProperty("DeviceId")
    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    @JsonProperty("Sign")
    public abstract String getSign();

    public Map<String, String> toFieldMap() {
        ObjectMapper mapper = JsonUtils.defaultMapper();
        Map<String, String> result;
        result = mapper.convertValue(this, new TypeReference<Map<String, String>>() {
        });
        return result;
    }
}